import socket
SERVER_IP = "localhost"
RECV_PORT = 19900
from utils import SocketCommunication
import pickle
from io import BytesIO
import time
from  io import BytesIO
import numpy as np
tools = SocketCommunication()
def recv_msg():
    try:
        #recv_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        #recv_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        #recv_socket.bind((SERVER_IP, RECV_PORT))
        recv_socket.listen(5)

        while True:
            try:
                #print("#############port listening", ins_port, self.ins_id,self.model_name,'$$$$$$$$$$$$$$$')
                ''''''
                conn,add = recv_socket.accept()
                data = tools.recv_data_bytes(conn)
                a = time.time()
                #request = pickle.loads(data)
                #request = np.load(BytesIO(data))['frame']
                b = time.time()
                print(round(b-a,3))
                #print("recv data",request.shape,round(b-a,3))
                conn.close()
            except Exception as e:
                print("error happens when receiving data",e)
    except Exception as e:
        print("error happens when assigning recv ports ",e)
recv_msg()